#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from launch import LaunchDescription
from launch.actions import GroupAction
from launch_ros.actions import Node, PushRosNamespace
import os
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    # 硬编码配置
    NAMESPACE = 'devices'  # 固定命名空间
    IFACE_NAME = 'wlp2s0'   # 固定网卡名
    
    pkg_share = get_package_share_directory('get_network_ip')
    devices_yaml = os.path.join(pkg_share, 'config', 'devices.yaml')

    return LaunchDescription([
        # 把内部所有节点都推入固定命名空间
        GroupAction([
            PushRosNamespace(NAMESPACE),  # 直接使用字符串

            Node(
                package='get_network_ip',
                executable='my_network_ip_node',
                name='my_network_ip_node',
                output='screen',
                parameters=[{'iface_name': IFACE_NAME}],  # 直接传递字符串
            ),

            Node(
                package='get_network_ip',
                executable='ping_devices_node',
                name='ping_devices_node',
                output='screen',
                parameters=[
                    {'config_path': devices_yaml},
                ],
            ),

            Node(
                package='get_network_ip',
                executable='combine_network_node',
                name='combine_network_node',
                output='screen',
            ),
        ])
    ])